home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 3863 / 3863.xpi / chrome / imacros.jar / content / ControlPanel.js < prev    next >
Text File  |  2010-01-25  |  10KB  |  5 lines

  1. //*/
  2. /*
  3. (c) Copyright 2008 iOpus Software GmbH - http://www.iopus.com
  4. */
  5. var dummy=null;function iMacrosControlPanel(){this.sidebar=null;this.registerObservers();};iMacrosControlPanel.prototype.registerObservers=function(){imns.osvc.addObserver(this,"imacros-sidebar-loaded",false);imns.osvc.addObserver(this,"imacros-sidebar-closed",false);};iMacrosControlPanel.prototype.unregisterObservers=function(){imns.osvc.removeObserver(this,"imacros-sidebar-loaded",false);imns.osvc.removeObserver(this,"imacros-sidebar-closed",false);};window.addEventListener("unload",function(){im_panel.unregisterObservers();},false);iMacrosControlPanel.prototype.observe=function(subject,topic,data){if(topic=="imacros-sidebar-loaded"){var t=document.getElementById("sidebar").contentWindow;if(t.location.href!="chrome://imacros/content/rec.xul")return;if(t==subject){this.sidebar=subject;this.sidebar.mainwindow=window;if(this.sidebarLoadedCallback){this.sidebarLoadedCallback();this.sidebarLoadedCallback=null;}this.updateSidebarState();}}else if(topic=="imacros-sidebar-closed"){if(subject==window){if(imacrosg){stop();alert("iMacros is closed. This will stop the "+"running Javascript file.");}this.sidebar=null;}}};iMacrosControlPanel.prototype.ensureSidebarIsOpen=function(callback){if(this.sidebarIsOpen)callback();else{im_Pref.setBoolPref("close-sidebar",true);this.sidebarLoadedCallback=callback;toggleSidebar("viewimacros");}};iMacrosControlPanel.prototype.closeSidebar=function(){if(!this.sidebar)return;toggleSidebar("viewimacros");};iMacrosControlPanel.prototype.__defineGetter__("sidebarIsOpen",function(){return! !this.sidebar;});iMacrosControlPanel.prototype.__defineGetter__("list",function(){if(this.sidebarIsOpen){var doc=this.sidebar.document;var list=doc.getElementById('listbox');return list;}return null;});iMacrosControlPanel.prototype.showLines=function(code){try{if(!this.sidebarIsOpen)return;var doc=this.sidebar.document;this.clearAllLines();if(code){var lines=code.split("\n");for(var i=0;i<lines.length;i++){this.list.appendItem(__strim(lines[i]));}}var box=doc.getElementById('boxlistbox');var tree=doc.getElementById('treeview');box.collapsed=false;tree.collapsed=true;var edit=doc.getElementById('editname');var rename=doc.getElementById('im-rename-button');edit.collapsed=true;rename.collapsed=true;this.list.scrollToIndex(0);}catch(e){Components.utils.reportError(e);}};iMacrosControlPanel.prototype.addLine=function(line){try{if(!this.sidebarIsOpen)return;this.list.appendItem(line);var count=this.list.getRowCount();this.list.ensureIndexIsVisible(count-1);}catch(e){Components.utils.reportError(e);}};iMacrosControlPanel.prototype.removeLastLine=function(){if(!this.sidebarIsOpen)return;this.list.removeItemAt(this.list.getRowCount()-1);};iMacrosControlPanel.prototype.highlightLine=function(line){this.statLine1=imacrosreplaystep+(line);if(!this.sidebarIsOpen)return;this.list.ensureIndexIsVisible(line-1);this.list.selectedIndex=line-1;};iMacrosControlPanel.prototype.clearAllLines=function(){if(!this.sidebarIsOpen)return;while(this.list.getRowCount())this.list.removeChild(this.list.firstChild);};iMacrosControlPanel.prototype.__defineSetter__("statLine1",function(str){if(!this.sidebarIsOpen)return;var doc=this.sidebar.document;var stat=doc.getElementById('replaystat');stat.value=str;});iMacrosControlPanel.prototype.__defineSetter__("statLine1Status",function(val){if(!this.sidebarIsOpen)return;var doc=this.sidebar.document;var stat=doc.getElementById('replaystat');if(/playing|recording/.test(val.toString())){stat.setAttribute("status",val);}else{stat.value="";stat.removeAttribute("status");}});iMacrosControlPanel.prototype.__defineSetter__("statLine2",function(str){if(!this.sidebarIsOpen)return;var doc=this.sidebar.document;var stat=doc.getElementById('delaystat');stat.value=str;});iMacrosControlPanel.prototype.__defineSetter__("statLine2Status",function(val){if(!this.sidebarIsOpen)return;var doc=this.sidebar.document;var stat=doc.getElementById('delaystat');if(/loading/.test(val.toString())){stat.setAttribute("loadCheck","true");}else{stat.value="";stat.removeAttribute("loadCheck");}});iMacrosControlPanel.prototype.showMacroTree=function(){try{var doc=this.sidebar.document;var box=doc.getElementById('boxlistbox');var tree=doc.getElementById('treeview');box.collapsed=true;tree.collapsed=false;this.statLine1Status="idle";this.statLine2Status="idle";if(im_Pref.getBoolPref("close-sidebar")){im_Pref.setBoolPref("close-sidebar",false);this.closeSidebar();}im_panel.updateSidebarState();}catch(e){Components.utils.reportError(e);}};iMacrosControlPanel.prototype.__defineGetter__("selectedItem",function(){if(!this.sidebarIsOpen)return null;var mtree=this.sidebar.getMTreeObject();return mtree.getSelectedItem();});iMacrosControlPanel.prototype.updateMacroTree=function(){if(this.sidebarIsOpen){this.sidebar.initMTree();}};iMacrosControlPanel.prototype.updateSidebarState=function(){if(!this.sidebarIsOpen)return;var doc=this.sidebar.document;var box=doc.getElementById('boxlistbox');var tree=doc.getElementById('treeview');var makeObject=function(constructor){var obj=new Object();for(var x=1;x<arguments.length;x++)obj[arguments[x]]=constructor(arguments[x]);return obj;};var butts=makeObject(function(name){return doc.getElementById("im-"+name+"-button");},"play","pause","stopplay","playloop","record","save","load","stoprecord","waitreplay","edit","share");var tabs=makeObject(function(name){return doc.getElementById("im-"+name+"-tab");},"play","record","edit");var off=function(obj){for(var x=1;x<arguments.length;x++)obj[arguments[x]].disabled=true;};var on=function(obj){for(var x=1;x<arguments.length;x++)obj[arguments[x]].disabled=null;};var tabbox=doc.getElementById("im-tabbox");if(mplayer.playing||imacrosg||imacrose=="playing"){off(butts,"play","playloop");on(butts,"pause","stopplay");off(tabs,"record","edit");tabbox.selectedIndex=0;butts["pause"].label=imacrose?imacrospause2dialog:imacrospause1dialog;if(!tree.collapsed&&mplayer.playing){this.showLines(mplayer.source);}}else if(imacrosc||imacrose=="recording"){off(butts,"record","save","load");on(butts,"stoprecord","waitreplay");off(tabs,"play","edit");tabbox.selectedIndex=1;if(!tree.collapsed){this.showLines(imacrosb.join("\n"));}}else{on(tabs,"play","record","edit");var item=this.selectedItem;if(item&& !item.isContainer){on(butts,"play","playloop","save","edit","share");}else{off(butts,"play","playloop","save","edit","share");}on(butts,"record","load");off(butts,"pause","stopplay","stoprecord","waitreplay");}var clicktype=im_Pref.getCharPref("clickmode");var elem=doc.getElementById("im-clickmode-label");if(elem){if(clicktype=="xy")elem.value="X/Y";else if(clicktype=="auto")elem.value="Auto";else if(clicktype=="htm")elem.value="HTM";else{elem.value="Auto";im_Pref.setCharPref("clickmode","auto");}}};iMacrosControlPanel.prototype.mboxClose=function(){if(!this.sidebar){Components.utils.reportError(new Error("Sidebar not found"));return;}var doc=this.sidebar.document;var deck=doc.getElementById("logo-message-deck");deck.selectedIndex=1;};iMacrosControlPanel.prototype.mboxHelp=function(){if(this.mboxErrorNumber==31415)iMacros.addTab("http://www.iopus.com/imacros/home/fx/rd.asp?helpid=macrotoolong");else iMacros.addTab("http://www.iopus.com/imacros/home/fx/e.asp?browser=fx&error="+this.mboxErrorNumber);};iMacrosControlPanel.prototype.mboxEdit=function(){steps(this.mboxErrorLine);};iMacrosControlPanel.prototype.mboxResetError=function(){if(!this.sidebar){Components.utils.reportError(new Error("Sidebar not found"));return;}var doc=this.sidebar.document;var box=doc.getElementById("imacros-message-box");var deck=doc.getElementById("logo-message-deck");if(deck.selectedIndex==0&&box.getAttribute("msgtype")=="error"){deck.selectedIndex=1;}};iMacrosControlPanel.prototype.showInfoMessage=function(msg){if(!this.sidebar){Components.utils.reportError(new Error("Sidebar not found"));return;}var doc=this.sidebar.document;var tabbox=doc.getElementById("im-tabbox");tabbox.selectedIndex=0;var deck=doc.getElementById("logo-message-deck");deck.selectedIndex=0;var msgbox=doc.getElementById("imacros-message-box");var help_btn=doc.getElementById("message-box-button-help");var edit_btn=doc.getElementById("message-box-button-edit");help_btn.collapsed=true;edit_btn.collapsed=true;msgbox.setAttribute("msgtype","message");msgbox.value=msg;};iMacrosControlPanel.prototype.showErrorMessage=function(msg,errnum){if(!this.sidebar){Components.utils.reportError(new Error("Sidebar not found"));return;}var doc=this.sidebar.document;var tabbox=doc.getElementById("im-tabbox");tabbox.selectedIndex=0;var deck=doc.getElementById("logo-message-deck");deck.selectedIndex=0;var msgbox=doc.getElementById("imacros-message-box");var help_btn=doc.getElementById("message-box-button-help");var edit_btn=doc.getElementById("message-box-button-edit");help_btn.collapsed=null;edit_btn.collapsed=null;msgbox.setAttribute("msgtype","error");msgbox.value=msg;this.mboxErrorNumber=errnum;this.mboxErrorLine=0;if(/, line:\s*(\d+)$/.test(msg))this.mboxErrorLine=parseInt(RegExp.$1);};iMacrosControlPanel.prototype.onLoopValueInput=function(){var textbox=this.sidebar.document.getElementById('im-loopval-textbox');textbox.value=textbox.value.replace(/^0+|[^\d]/g,"");};iMacrosControlPanel.prototype.onLoopValueChange=function(){var textbox=this.sidebar.document.getElementById('im-loopval-textbox');if(!textbox.value.length)textbox.value="3";};iMacrosControlPanel.prototype.__defineGetter__("maxLoopValue",function(){if(!this.sidebarIsOpen)return 0;var doc=this.sidebar.document;var value=doc.getElementById('im-loopval-textbox');return __int(value.value);});iMacrosControlPanel.prototype.__defineSetter__("currentLoopValue",function(val){if(!this.sidebarIsOpen)return;var doc=this.sidebar.document;var value=doc.getElementById('im-curloop-textbox');value.value=val;});var im_panel=new iMacrosControlPanel();